/*
 * Copyright (C) 2015-2017 Alibaba Group Holding Limited
 */


#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>

#include "aos/init.h"
#include "aos/kernel.h"
#include <k_api.h>

#include "aos/hal/uart.h"

#include "board.h"
#include "fsl_gpio.h"
#include "pin_mux.h"


#define AOS_START_STACK 4096


#define us2tick(us) \
    ((us * RHINO_CONFIG_TICKS_PER_SECOND + 999999) / 1000000)

ktask_t *g_aos_app;

static void sys_init(void)
{
    kinit_t kinit;

    kinit.argc = 0;
    kinit.argv = NULL;
    kinit.cli_enable = 1;

    platform_init();

    /* this is must as this will calulated the actual CPU Main Freq */
    SystemCoreClockUpdate();

    SysTick_Config(SystemCoreClock / RHINO_CONFIG_TICKS_PER_SECOND);

    ok1061s_peripheral_init();

    board_flash_partition_init();

    aos_components_init(&kinit);
#ifndef AOS_BINS
    application_start(kinit.argc, kinit.argv);  /* jump to app/example entry */
#endif
}

void hal_reboot(void)
{
    NVIC_SystemReset();
}

int main(void)
{
    aos_heap_set();

    aos_init();

    krhino_task_dyn_create(&g_aos_app, "aos-init", 0, AOS_DEFAULT_APP_PRI , 0, AOS_START_STACK, (task_entry_t)sys_init, 1);


    aos_start();
   return 0;
}

